package com.nf.mvc;

import com.nf.mvc.view.PlainViewResult;
import com.nf.mvc.view.VoidViewResult;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public abstract class ViewResult {
    public abstract void render(HttpServletRequest req, HttpServletResponse resp) throws Exception;


    public static ViewResult adaptHandlerResult(Object handleResult) {
        ViewResult viewResult;
        if (handleResult == null) {
            viewResult = new VoidViewResult();
        } else if (handleResult instanceof ViewResult) {
            viewResult = (ViewResult) handleResult;
        } else {
            viewResult = new PlainViewResult(handleResult.toString());
        }
        return viewResult;
    }
}
